const { ccclass, property } = cc._decorator;
import s from "./EventMgr"
import c from "./MatchGameEventType"
import u from "./frameworkManager"
import d from "./EngineUtil"
import h, { MatchGameStatus } from "./MatchGameData"
import f from "./MatchGameConfig"
import g, { ObstacleAllType } from "./ObstacleConfig"
import y from "./MatchGameAudioMgr"
import m from "./MatchGameDataMgr"
import _ from "./MatchGameLogicDataCtrl"
import b from "./UiManage"
import C from "./MatchGameGuidePage"
import T from "./SkillAniCtrl"
import M from "./EmptyObstacleItemCtrl"
import P from "./MultiObstaclePrefabCtrl"
import S from "./MatchGameCenterCtrl"
import w, { PandaStatu } from "./MatchGameViewCtrl";
import MatchGameConfig from "./MatchGameConfig";
import UiManager from "./UiManage";
import BasePageCtrl, { AnimType } from "./BasePageCtrl";

export enum GuideElimitateType {
    Null = -1,
    Up = 1,
    Down = 2,
    Left = 3,
    Right = 4,
    Click = 5,
    Any = 6
}

export enum GuideType {
    Target = 1,
    Step = 2,
    Match = 3,
    Prop = 4,
    Obstacle = 5,
    GoldCoin = 6,
    Arrow = 7,
    Gun = 8,
    Hammer = 9
}

@ccclass
export default class MatchGameGuidePageCtrl extends BasePageCtrl {

    public guideInfoArr = [];
    public curGuideInfo = null;
    public guideIndex = 0;
    public middleNodeArr = [];
    public topNodeArr = [];
    public bottomNodeArr = [];
    public mulNodesArr = [];
    public blockClick = false;
    public pandaStatu = null;
    public noticeBg = null;
    public druingShowGuide = false;
    public _touchControl = false;
    public _hasPeneLock = false;
    public _hasBlack = false;
    public _hasTouchLock = false;
    public _hasBlackTouch = false;
    public _reuse = false;
   
    public onLoad() {
        this.onUILoad();
        this._animType = AnimType.NONE;
        this._touchControl = false;
        this._hasPeneLock = false;
        this._hasBlack = false;
        this._hasTouchLock = false;
        this._hasBlackTouch = false;
        this._reuse = false;
        this.noticeBg = w.instance.ui.top_center_bg.getChildByName("panda_1").getChildByName("notice_bg");
        super.onLoad();
        this.addButtonListen();
        this.addEvent();
        this.initPanda();
        this.initTestBtnShow();
        s.listen(c.GUIDE_ELIMINATE, this.onGuideEliminate, this);
        s.listen(c.SHOW_NOTICE, this.showNotice, this);
    };
    public start() { };
    public onUILoad() {
        this.ui = this.node.addComponent(C);
    };
    public _init(e?) {
        var t = this;
        this.druingShowGuide = false;
        h.duringGuide = true;
        this.node.setContentSize(cc.winSize);
        this.guideIndex = 0;
        var a = e.guideInfoArr;
        this.guideInfoArr = a;
        u.log("引导数据", this.guideInfoArr);
        this.scheduleOnce(function () {
            t.showGuide();
        }, .2);
    };
    public initTestBtnShow() {
        this.ui.testBtn.active = true;//!p.getInstance().isOnlineRelease();
    };
    public addEvent() {
        s.listen(c.ON_GUIDE_ELIMITATE, this.oneGuideFinish, this);
        s.listen(c.ELIMINATE_FINISH, this.guideNext, this);
        s.listen(c.GUIDE_OVER, this.guideOver, this);
        s.listen(c.ELIMINATE_STATUS, this.setPandaElimateStatus, this);
        s.listen(c.ELIMINATE_FINISH, this.onElimateFinish, this);
        s.listen(c.ON_TARGET_FINISH, this.onFinishTarget, this);
        this.ui.swallowTouch.on(cc.Node.EventType.TOUCH_START, this.oneGuideFinish, this);
        this.ui.nextGuideBtn.on(cc.Node.EventType.TOUCH_START, this.finishAndNextGuide, this);
        this.ui.btn_skillPass.on(cc.Node.EventType.TOUCH_START, this.oneGuideFinish, this);
    };
    public removeEvent() {
        s.ignore(c.ON_GUIDE_ELIMITATE, this.oneGuideFinish, this);
        s.ignore(c.ELIMINATE_FINISH, this.guideNext, this);
        s.ignore(c.GUIDE_OVER, this.guideOver, this);
        s.ignore(c.ELIMINATE_STATUS, this.setPandaElimateStatus, this);
        s.ignore(c.ELIMINATE_FINISH, this.onElimateFinish, this);
        s.ignore(c.ON_TARGET_FINISH, this.onFinishTarget, this);
        this.ui.swallowTouch.off(cc.Node.EventType.TOUCH_START, this.oneGuideFinish, this);
        this.ui.nextGuideBtn.off(cc.Node.EventType.TOUCH_START, this.finishAndNextGuide, this);
        this.ui.btn_skillPass.off(cc.Node.EventType.TOUCH_START, this.oneGuideFinish, this);
    };
    public onDestroy() {
        this.removeEvent();
    };
    public showGuide() {
        h.setEnableMultiTouch(true);
        m.closeSquareGuide();
        this.druingShowGuide = true;
        this.ui.contentNode.active = true;
        this.curGuideInfo = this.guideInfoArr[this.guideIndex];
        if(!this.curGuideInfo){
            this.hide();
            return;
        }
        u.log("this.curGuideInfo", this.curGuideInfo);
        var e = this.curGuideInfo, t = e.step, a = e.arrows, o = e.handInfo, i = e.guideType, r = e.showPande, n = e.MatchGuideArr, p = e.bottoms, d = e.tipInfo, f = e.obstacleType, _ = e.bottomAllUp, v = e.skillPass, b = e.swallowTouch;
        this.initAllNodes();
        this.setArrows(a);
        this.setHand(o);
        this.showPanda(r);
        this.blockClick = false;
        this.setMatchArr(n);
        if (i == GuideType.Target) {
            this.ui.basePanelLock.active = true;
            if (2 == t) {
                this.ui.swallowTouch.active = true;
                this.showTarget(true);
            } else this.ui.nextGuideBtn.active = true;
        } else if (i == GuideType.GoldCoin) {
            this.ui.basePanelLock.active = true;
            this.ui.nextGuideBtn.active = true;
            this.addGoldCoinNode();
            y.playCoinGuideAudio();
        } else if (i == GuideType.Hammer) this.addHammerNode(); else if (i == GuideType.Arrow) {
            if (1 == this.guideIndex) {
                this.ui.arrow_guide_tip.active = true;
                s.trigger(c.HIDE_SKILL_USE_PAGE);
            } else 0 == this.guideIndex && (this.ui.nextGuideBtn.active = true);
            this.addArrowNode();
        } else if (i == GuideType.Gun) {
            1 == this.guideIndex ? this.ui.gun_guide_tip.active = true : 0 == this.guideIndex && (this.ui.nextGuideBtn.active = true);
            this.addGunNode();
        } else if (i == GuideType.Obstacle) {
            this.ui.basePanelLock.active = true;
            this.blockClick = true;
            this.setObstacleArr(f);
            if (f == ObstacleAllType.GoldCoin || f == ObstacleAllType.Egg || f == ObstacleAllType.Oyster || ObstacleAllType.Grass) {
                this.ui.swallowTouch._touchListener.setSwallowTouches(false);
                this.ui.swallowTouch.zIndex = 100;
            } else if (f == ObstacleAllType.Vase) {
                this.ui.swallowTouch._touchListener.setSwallowTouches(true);
                this.ui.swallowTouch.zIndex = 100;
            } else this.ui.swallowTouch._touchListener.setSwallowTouches(true);
            if (f == ObstacleAllType.GoldCoin) {
                this.showTarget(true);
                this.showStep(true);
            }
        }
        this.setRichText(d);
        this.setBottoms(p);
        _ && this.upAllBottomBg();
        if (b) {
            this.ui.swallowTouch.active = true;
            this.blockClick = false;
        }
        if (v) {
            this.ui.btn_skillPass.active = true;
            this.blockClick = false;
        }
    };
    public initAllNodes() {
        this.ui.bottomBgParent.removeAllChildren();
        this.ui.bottomGridParent.removeAllChildren();
        this.ui.middleGridParent.removeAllChildren();
        this.ui.topGridParent.removeAllChildren();
        this.ui.topNodes.removeAllChildren();
        this.ui.multiAreaParent.removeAllChildren();
        this.ui.allBottomBgParent.removeAllChildren();
        var e = d.getNodeAToNodeBPoint(S._instance.node, this.node);
        u.log("bottomBgParent位置---", e);
        this.ui.bottomBgParent.setPosition(cc.v3(e));
        this.ui.bottomGridParent.setPosition(cc.v3(e));
        this.ui.middleGridParent.setPosition(cc.v3(e));
        this.ui.topGridParent.setPosition(cc.v3(e));
        this.ui.multiAreaParent.setPosition(cc.v3(e));
        this.ui.arrowParent.setPosition(cc.v3(e));
        this.ui.allBottomBgParent.setPosition(cc.v3(e));
        this.ui.rich_guide.getComponent(cc.RichText).string = "";
        this.ui.guideHand.active = false;
        this.ui.arrowParent.active = true;
        this.ui.guide_arrow.active = false;
        this.ui.arrow_guide_tip.active = false;
        this.ui.gun_guide_tip.active = false;
        this.ui.swallowTouch.active = false;
        this.ui.nextGuideBtn.active = false;
        this.ui.btn_skillPass.active = false;
        this.ui.basePanelLock.active = false;
        this.middleNodeArr = [];
        this.topNodeArr = [];
        this.bottomNodeArr = [];
        this.blockClick = false;
        this.ui.pandaParent.active = true;
        var t = d.getNodeAToNodeBPoint(w.instance.ui.top_center_bg, this.ui.pandaParent);
        this.ui.pandaParent.setPosition(cc.v3(t));
        this.ui.swallowTouch._touchListener.setSwallowTouches(false);
    };
    public setArrows(e) {
        this.ui.arrowParent.removeAllChildren();
        this.ui.guide_arrow.active = false;
        if (e) if (e.length) for (var t = 0; t < e.length; t++) {
            var a = cc.instantiate(this.ui.guide_arrow);
            this.setOneArrow(e[t], a);
        } else this.ui.guide_arrow.active = false;
    };
    public setOneArrow(e, t) {
        t.parent = this.ui.arrowParent;
        t.active = true;
        var a = e.pos, o = e.dire;
        1 == o ? t.angle = 0 : 2 == o ? t.angle = 90 : 3 == o ? t.angle = 180 : 4 == o && (t.angle = -90);
        u.log("pos===", e, 299 + (cc.winSize.height - 1280) / 2);
        t.position = a;
        if (this.curGuideInfo.guideType == GuideType.Target) {
            var i = d.getNodeAToNodeBPoint(w.instance.ui.matchTargetBg, t);
            t.position = cc.v3(i.x, i.y - 200);
        } else if (this.curGuideInfo.guideType == GuideType.GoldCoin) {
            var r = d.getNodeAToNodeBPoint(w.instance.ui.hb_node, t);
            t.position = cc.v3(r.x, r.y + 200);
        } else if (this.curGuideInfo.guideType == GuideType.Hammer) {
            var n = d.getNodeAToNodeBPoint(w.instance.ui.hammer_node, t);
            t.position = cc.v3(n.x, n.y + 200);
        } else if (this.curGuideInfo.guideType == GuideType.Arrow) {
            var s = d.getNodeAToNodeBPoint(w.instance.ui.arrow_node, t);
            t.position = cc.v3(s.x, s.y + 200);
        } else if (this.curGuideInfo.guideType == GuideType.Gun) {
            var c = d.getNodeAToNodeBPoint(w.instance.ui.gun_node, t);
            t.position = cc.v3(c.x, c.y + 200);
        }
        this.playArrowAni(t);
    };
    public playArrowAni(e) {
        cc.tween(e).repeatForever(cc.tween().by(.5, {
            y: 20
        }).by(.5, {
            y: -20
        })).start();
    };
    public setRichText(e) {
        if (e) {
            this.ui.guide_tip_bg.active = true;
            var t = e.pos, a = e.str;
            this.ui.guide_tip_bg.setPosition(t);
            this.ui.rich_guide.getComponent(cc.RichText).string = a;
            if (this.curGuideInfo.guideType == GuideType.Obstacle) {
                this.ui.rich_guide.getComponent(cc.RichText).fontSize = 37;
                20 == h.gameLevel && (this.ui.rich_guide.getComponent(cc.RichText).fontSize = 35);
                41 == h.gameLevel && (this.ui.rich_guide.getComponent(cc.RichText).fontSize = 32);
            } else this.ui.rich_guide.getComponent(cc.RichText).fontSize = 32;
        } else this.ui.guide_tip_bg.active = false;
    };
    public setHand(e) {
        if (e) {
            var t = e.pos, a = e.type;
            if (e) {
                this.ui.guideHand.active = true;
                var o = d.getNodeAToNodeBPoint(S._instance.ui.MiddleParents, this.node);
                o.x += MatchGameConfig.ITEM_WIDTH / 2;
                o.y -= MatchGameConfig.ITEM_HEIGHT / 2;
                var i = cc.Vec3.add(cc.v3(), cc.v3(o), t);
                this.ui.guideHand.setPosition(i);
                var r = this.ui.guideHand.getComponent(sp.Skeleton);
                1 == a ? r.setAnimation(0, "RightSlide", true) : 2 == a ? r.setAnimation(0, "Glide", true) : 3 == a ? r.setAnimation(0, "Click", true) : 4 == a ? r.setAnimation(0, "LeftSlide", true) : 5 == a && r.setAnimation(0, "SlideUp", true);
            } else this.ui.guideHand.active = false;
        }
    };
    public setMatchArr(e) {
        if (e && e.length) {
            var t = m.middleSquareGrid;
            if (e.length) for (var a = 0; a < e.length; a++) {
                var o = e[a], i = o.pos, r = o.moveType, n = (o.squareType, i.row), s = i.col;
                if (t[n] && t[n][s] && t[n][s].node) {
                    var c = t[n][s].node;
                    this.setSquareParent(c);
                    c.getComponent("MatchItemPrefabCtrl") ? c.getComponent("MatchItemPrefabCtrl").setGuideElimitateType(r) : c.getComponent("PropPrefabCtrl") && c.getComponent("PropPrefabCtrl").setGuideElimitateType(r);
                    this.curGuideInfo.guideType == GuideType.Hammer ? c.on(cc.Node.EventType.TOUCH_END, this.useHammer, this) : this.curGuideInfo.guideType == GuideType.Arrow ? c.on(cc.Node.EventType.TOUCH_END, this.useArrow, this) : this.curGuideInfo.guideType == GuideType.Gun && c.on(cc.Node.EventType.TOUCH_END, this.useGun, this);
                }
            }
        }
    };
    public setObstacleArr(e) {
        var t = this;
        u.log("setObstacleArr");
        if (e) {
            for (var a = m.middleSquareGrid, o = S._instance.displayMapInfo, i = S._instance.bottomSquareGrid, r = S._instance.topSquareGrid, l = S._instance.multiAreaParent, s = [], c = 0; c < f.MAX_ROW; c++) if (o[c]) for (var p = 0; p < f.MAX_COL; p++) if (o[c][p]) {
                var d = false;
                if (i[c][p] && i[c][p].node && i[c][p].squareType == f.SquareType.ObstacleItem && i[c][p].itemType == e) {
                    s.push(i[c][p]);
                    d = true;
                }
                if (a[c][p] && a[c][p].node) {
                    if (d) {
                        a[c][p].getComponent("MatchItemPrefabCtrl") && a[c][p].getComponent("MatchItemPrefabCtrl").setGuideElimitateType(GuideElimitateType.Any);
                        s.push(a[c][p]);
                        continue;
                    }
                    if (a[c][p].squareType == f.SquareType.ObstacleItem && a[c][p].itemType == e && !a[c][p].node.getComponent(M)) {
                        s.push(a[c][p]);
                        continue;
                    }
                }
                r[c][p] && r[c][p].node && r[c][p].squareType == f.SquareType.ObstacleItem && r[c][p].itemType == e && s.push(r[c][p]);
            }
            l.children.forEach(function (t) {
                t.getComponent(P) && t.getComponent(P).itemType == e && s.push(t.getComponent(P));
            });
            s.length ? s.forEach( (e) => {
                t.setSquareParent(e.node);
            }) : u.log("找不到障碍物引导");
        } else u.log("没有障碍物引导");
    };
    public setBottoms(e) {
        var t = this;
        this.ui.bottomBgParent.removeAllChildren();
        e && e.forEach( (e) => {
            var a = e.pos, o = e.path, i = a.row, r = a.col, n = cc.instantiate(t.ui.spr_bottom);
            n.active = true;
            var l = "imgs/game/guide_bg/" + o;
            UiManager.loadSpriteFrameInDeepPath(n.getComponent(cc.Sprite), l);
            n.parent = t.ui.bottomBgParent;
            var s = cc.v3(i * MatchGameConfig.ITEM_WIDTH - MatchGameConfig.ITEM_WIDTH /2, -r * MatchGameConfig.ITEM_HEIGHT + MatchGameConfig.ITEM_WIDTH /2);
            n.position = s;
            t.curGuideInfo.obstacleType == ObstacleAllType.Oyster && t.scheduleOnce(function () {
                n.height = 702;
            });
        });
    };
    public oneGuideFinish() {
        if (this.druingShowGuide) {
            this.druingShowGuide = false;
            this.ui.contentNode.active = false;
            this.resetSquareParent();
            this.guideIndex++;
            u.log("oneGuideFinish", this.guideIndex);
            if (this.guideIndex >= this.guideInfoArr.length) this.guideOver(); else {
                u.log("oneGuideFinish", "22222");
                var e = this.curGuideInfo.step;
                if (this.curGuideInfo.guideType == GuideType.Target && 2 == e) {
                    h.duringGuide = false;
                    this.ui.basePanelLock.active = false;
                    m.getMatchGuideData();
                }
            }
        }
    };
    public guideNext() {
        var e = this;
        u.log("this.druingShowGuide==", this.druingShowGuide);
        if (!this.druingShowGuide) {
            u.log("guideNext", this.guideIndex);
            if (this.guideIndex >= this.guideInfoArr.length) this.guideOver(); else if (h.duringGuide && 4 == h.gameLevel && 3 == this.guideIndex) {
                this.druingShowGuide = true;
                m.setGlobalScheduler(function () {
                    u.log("第四关延迟处理");
                    e.showGuide();
                }, .2);
            } else this.showGuide();
        }
    };
    public finishAndNextGuide() {
        this.guideIndex++;
        u.log("finishAndNextGuide", this.guideIndex);
        this.guideIndex >= this.guideInfoArr.length ? this.guideOver() : this.showGuide();
    };
    public guideOver() {
        var e = this;
        if(!this.curGuideInfo){
            e.hide();
            return;
        }
        this.curGuideInfo.guideType == GuideType.GoldCoin && y.stopCoinGuideAudio();
        h.duringGuide = false;
        h.setEnableMultiTouch(false);
        this.curGuideInfo.guideType != GuideType.Hammer && this.curGuideInfo.guideType != GuideType.Arrow && this.curGuideInfo.guideType != GuideType.Gun || s.trigger(c.UP_SKILL);
        this.scheduleOnce(function () {
            e.hide();
        });
        m.getMatchGuideData();
    };
    public setSquareParent(e) {
        var t, a = S._instance.ui.MiddleParents, o = S._instance.ui.MiddleDropMask, i = S._instance.ui.LowestParent, r = S._instance.ui.TopParents, n = S._instance.ui.multiAreaParent;
        t = e.parent == a || e.parent == o ? this.ui.middleGridParent : e.parent == i ? this.ui.bottomGridParent : e.parent == r ? this.ui.topGridParent : e.parent == n ? this.ui.multiAreaParent : this.ui.middleGridParent;
        e.parent = t;
    };
    public resetSquareParent() {
        var e = this;
        u.log("resetSquareParent--");
        var t = S._instance.ui.MiddleParents, a = S._instance.ui.LowestParent, o = S._instance.ui.TopParents, i = S._instance.ui.multiAreaParent, r = [], n = [], l = [], s = [];
        this.ui.bottomGridParent.children.forEach( (e) => {
            n.push(e);
        });
        this.ui.middleGridParent.children.forEach( (e) => {
            r.push(e);
        });
        this.ui.topGridParent.children.forEach( (e) => {
            l.push(e);
        });
        this.ui.multiAreaParent.children.forEach( (e) => {
            s.push(e);
        });
        r.forEach(function (a) {
            a.parent = t;
            a.targetOff(e);
        });
        n.forEach(function (t) {
            t.parent = a;
            t.targetOff(e);
        });
        l.forEach(function (t) {
            t.parent = o;
            t.targetOff(e);
        });
        s.forEach(function (t) {
            t.parent = i;
            t.targetOff(e);
        });
        this.showPanda(false);
        this.showTarget(false);
        this.showStep(false);
    };
    public addButtonListen() {
        UiManager.addButtonListen(this.ui.blockNode, this.clickBlock, this);
        UiManager.addButtonListen(this.ui.testBtn, this.allGuideFinish, this);
    };
    public clickBlock() {
        this.blockClick && this.guideNext();
    };
    public allGuideFinish() {
        var e = this;
        this.resetSquareParent();
        s.trigger(c.UP_SKILL);
        this.scheduleOnce(function () {
            e.hide();
        });
        h.duringGuide = false;
        h.setEnableMultiTouch(false);
        m.getMatchGuideData();
    };
    public addTargetNode() {
        var e = this;
        u.log("addTargetNode---");
        this.scheduleOnce(function () {
            var t = w.instance.ui.matchTargetBg;
            w.instance.ui;
            var a = cc.instantiate(t);
            a.parent = e.ui.topNodes;
            a.position = cc.v3(d.getNodeAToNodeBPoint(t, a));
        });
    };
    public showTarget(e) {
        if (e) {
            var t = w.instance.ui.matchTargetBg, a = cc.v3(d.getNodeAToNodeBPoint(t, this.ui.targetParent));
            if (t) {
                u.log("showTarget");
                t.parent = this.ui.targetParent;
                t.position = a;
            }
        } 
        else if (t = this.ui.targetParent.getChildByName("matchTargetBg")) {
            t.parent = w.instance.ui.top;
            t.position = cc.v3(-107, -21);
            t.zIndex = -1;
        }
    };
    public showStep(e) {
        if (e) {
            var t = w.instance.ui.matchStepBg, a = cc.v3(d.getNodeAToNodeBPoint(t, this.ui.stepParent));
            if (t) {
                u.log("showStep");
                t.parent = this.ui.stepParent;
                t.position = a;
            }
        } else if (t = this.ui.stepParent.getChildByName("matchStepBg")) {
            t.parent = w.instance.ui.top;
            t.position = cc.v3(255, -22.5);
            t.zIndex = -1;
        }
    };
    public showPanda(e) {
        var t = this.ui.pandaParent.getChildByName("panda_1");
        t && (t.active = 1 == e);
        var a = w.instance.ui.top_center_bg.getChildByName("panda_1");
        a && (a.active = 0 == e);
        if (this.noticeBg) {
            this.noticeBg.parent = e ? this.ui.pandaParent.getChildByName("panda_1") : w.instance.ui.top_center_bg.getChildByName("panda_1");
            this.noticeBg.y = -68;
        }
    };
    public addGoldCoinNode() {
        var e = this;
        this.scheduleOnce(function () {
            var t = w.instance.ui.hb_node, a = cc.instantiate(t);
            a.parent = e.ui.topNodes;
            a.position = cc.v3(d.getNodeAToNodeBPoint(t, a));
        });
    };
    public addHammerNode() {
        var e = this;
        this.scheduleOnce(function () {
            var t = w.instance.ui.hammer_node, a = cc.instantiate(t);
            a.parent = e.ui.topNodes;
            a.position = cc.v3(d.getNodeAToNodeBPoint(t, a));
            a.getChildByName("btn_hammer").getComponent(cc.Button).enabled = false;
            u.log("addHammerNode", a);
            a.on(cc.Node.EventType.TOUCH_END, e.touchHammer, e);
        });
    };
    public addArrowNode() {
        var e = this;
        this.scheduleOnce(function () {
            var t = w.instance.ui.arrow_node, a = cc.instantiate(t);
            a.parent = e.ui.topNodes;
            a.position = cc.v3(d.getNodeAToNodeBPoint(t, a));
            a.getChildByName("btn_arrow").getComponent(cc.Button).enabled = false;
            u.log("addArrowNode", a);
            a.on(cc.Node.EventType.TOUCH_END, e.touchArrow, e);
        });
    };
    public touchHammer() {
        this.guideIndex > 0 || this.finishAndNextGuide();
    };
    public useHammer() {
        var e = this.curGuideInfo.MatchGuideArr[0], t = e.pos, a = (e.moveType, e.squareType,
            t.row), o = t.col;
        T.playHammer({
            row: a,
            col: o
        }, function () { });
        _.useHammer({
            row: a,
            col: o
        });
        this.oneGuideFinish();
    };
    public touchArrow() {
        this.finishAndNextGuide();
    };
    public useArrow() {
        var e = this.curGuideInfo.MatchGuideArr[0], t = e.pos, a = (e.moveType, e.squareType,
            t.row), o = t.col;
        _.useArrow({
            row: a,
            col: o
        });
        this.oneGuideFinish();
    };
    public addGunNode() {
        var e = this;
        this.scheduleOnce(function () {
            var t = w.instance.ui.gun_node, a = cc.instantiate(t);
            a.parent = e.ui.topNodes;
            a.position = cc.v3(d.getNodeAToNodeBPoint(t, a));
            a.getChildByName("btn_gun").getComponent(cc.Button).enabled = false;
            u.log("addArrowNode", a);
            a.on(cc.Node.EventType.TOUCH_END, e.touchGun, e);
        });
    };
    public touchGun() {
        this.finishAndNextGuide();
    };
    public useGun(e) {
        u.log("event---", e);
        var t = e.target;
        if (t.getComponent("ObstaclePrefabCtrl")) {
            var a = t.getComponent("ObstaclePrefabCtrl"), o = a._row, i = a._col;
            _.useGun({
                row: o,
                col: i
            });
            this.oneGuideFinish();
        }
    };
    public getV3Pos(e) {
        var t = e.row, a = e.col;
        return cc.v3(t * MatchGameConfig.ITEM_WIDTH + MatchGameConfig.ITEM_WIDTH / 2, -a * MatchGameConfig.ITEM_HEIGHT - MatchGameConfig.ITEM_HEIGHT / 2);
    };
    public getRowColByPos(e) {
        var t, a, o = e.x, i = e.y;
        t = Math.floor(o / MatchGameConfig.ITEM_WIDTH);
        a = Math.floor(-i / MatchGameConfig.ITEM_HEIGHT);
        return t >= 0 && t <= f.MAX_ROW && a >= 0 && a <= f.MAX_COL && S._instance.displayMapInfo[t][a] ? {
            row: t,
            col: a
        } : null;
    };
    public upAllBottomBg() {
        var e = S._instance.ui.bottomBgParent;
        cc.instantiate(e).parent = this.ui.allBottomBgParent;
    };
    public initPanda() {
        var e = this;
        this.setPandaIdleStatu();
        var t = cc.isValid(this.ui.panda_1) && this.ui.panda_1.getComponent(sp.Skeleton);
        t && t.setCompleteListener(function () {
            e.onPandaSpCompleteListener();
        });
        this.unschedule(this.setPandathinkStatus);
        this.scheduleOnce(this.setPandathinkStatus, 3);
    };
    public onPandaSpCompleteListener() {
        var e = cc.isValid(this.ui.panda_1) && this.ui.panda_1.getComponent(sp.Skeleton);
        if (e) {
            var t = e.animation;
            if (this.pandaStatu == PandaStatu.thinking) {
                if ("think" == t) {
                    e.setAnimation(0, "idle_3", false);
                    e.addAnimation(0, "idle_1", false);
                    e.addAnimation(0, "think", false);
                }
            } else this.pandaStatu == PandaStatu.Idle ? this.setPandaIdleStatu() : this.pandaStatu == PandaStatu.Elimate ? "idle_4" == t && this.setPandaIdleStatu() : this.pandaStatu == PandaStatu.victory ? "victory" == t && this.setPandaIdleStatu() : (this.pandaStatu,
                PandaStatu.Fail);
        }
    };
    public setPandaFailStatu() {
        this.pandaStatu = this.pandaStatu.Fail;
        var e = cc.isValid(this.ui.panda_1) && this.ui.panda_1.getComponent(sp.Skeleton);
        e && e.setAnimation(0, "unhappy", true);
    };
    public onFinishTarget() {
        this.setPandavictoryStatu();
    };
    public setPandavictoryStatu() {
        if (this.pandaStatu != PandaStatu.victory) {
            this.pandaStatu = PandaStatu.victory;
            var e = cc.isValid(this.ui.panda_1) && this.ui.panda_1.getComponent(sp.Skeleton);
            e && e.setAnimation(0, "victory", false);
        }
    };
    public setPandaIdleStatu() {
        this.pandaStatu = PandaStatu.Idle;
        if (this.ui.panda_1) try {
            var e = cc.isValid(this.ui.panda_1) && this.ui.panda_1.getComponent(sp.Skeleton);
            e && e.setAnimation(0, "idle_1", true);
        } catch (e) {
            u.log("setPandaIdleStatu==", e);
        }
    };
    public setPandathinkStatus() {
        if (h.gameStatus === MatchGameStatus.DuringGame && this.pandaStatu != PandaStatu.thinking) {
            this.pandaStatu = PandaStatu.thinking;
            var e = cc.isValid(this.ui.panda_1) && this.ui.panda_1.getComponent(sp.Skeleton);
            if (e) {
                e.setAnimation(0, "idle_3", false);
                e.addAnimation(0, "idle_1", false);
                e.addAnimation(0, "think", false);
            }
        }
    };
    public setPandaElimateStatus() {
        if (h.gameStatus === MatchGameStatus.DuringGame && this.pandaStatu != PandaStatu.Elimate) {
            this.pandaStatu = PandaStatu.Elimate;
            var e = cc.isValid(this.ui.panda_1) && this.ui.panda_1.getComponent(sp.Skeleton);
            if (e) {
                e.setAnimation(0, "idle_2", false);
                e.addAnimation(0, "idle_4", false);
            }
        }
    };
    public onElimateFinish() {
        if (h.gameStatus == MatchGameStatus.DuringGame) {
            this.unschedule(this.setPandathinkStatus);
            this.scheduleOnce(this.setPandathinkStatus, 3);
        }
    };
    public onGuideEliminate() {
        this.ui.basePanelLock.active = true;
    };
    public showNotice() { };
    static prefabUrl = "MatchGameGuidePage";
    static className = "MatchGameGuidePageCtrl";
}
